package lq.common.handler;

import lq.common.entity.StudyResponse;
import lq.common.utils.StudyUtil;
import org.springframework.http.MediaType;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @program: cloud-study
 * @description:
 * @author: LQ
 * @create: 2020-09-29 16:44
 */

public class StudyAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
        StudyUtil.makeResponse(httpServletResponse,MediaType.APPLICATION_JSON_UTF8_VALUE,HttpServletResponse.SC_FORBIDDEN,new StudyResponse().message("没有权限访问该资源"));
    }
}
